package com.cyy.demo.classtest.applicationContextAware;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
@Data
public class MyApplicationContextAware implements ApplicationContextAware {


    private Map<String, HandlerData> beanMap = new HashMap<>();


    /**
     * 容器初始化的时候执行
     * @param applicationContext
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("执行setApplicationContext()方法 #########################################)");
        beanMap = applicationContext.getBeansOfType(HandlerData.class);
        beanMap.forEach((key,value)-> System.out.println(key+":"+value.toString()));
    }


}
